/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2020, LomboTech Co.Ltd.
 * Author: lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 */
#ifndef __LOMBO_REGULATOR_H__
#define __LOMBO_REGULATOR_H__

#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/regmap.h>

#define DISCRETE_LDO_REG(_name, _family, _id, _supply) \
[_family##_ID_##_id] = {		\
.name			= _name,	\
.supply_name		= _supply,	\
.of_match		= of_match_ptr("REG_"#_id),	\
.regulators_node = of_match_ptr("regulators"),	\
.id			= _family##_ID_##_id,	\
.type			= REGULATOR_VOLTAGE,	\
.ops			= &lombo_ldo_regulator_ops,	\
.enable_reg		= _family##_##_id##_CTRL,	\
.enable_mask	= _family##_##_id##_EN_MASK,\
.owner			= THIS_MODULE,	\
	}

#define PMIC_DCDC_REG(_name, _family, _id, _supply,	\
		_minuV, _uvS, _minSel)		\
[_family##_ID_##_id] = {		\
.name			= _name,	\
.supply_name		= _supply,	\
.of_match		= of_match_ptr("REG_"#_id),	\
.regulators_node = of_match_ptr("regulators"),	\
.id			= _family##_ID_##_id,	\
.type			= REGULATOR_VOLTAGE,	\
.ops			= &lombo_dcdc_regulator_ops,	\
.n_voltages		= _family##_##_id##_NUM_VOLTAGES,\
.min_uV			= _minuV,		\
.uV_step		= _uvS,			\
.linear_min_sel = _minSel,		\
.vsel_reg		= _family##_##_id##_VREG, \
.vsel_mask		= _family##_##_id##_##VREG_MASK,\
.enable_reg		= _family##_##_id##_CTRL,	\
.enable_mask	= _family##_##_id##_EN_MASK,\
.owner			= THIS_MODULE,	\
	}

#define PMIC_LDO_REG(_name, _family, _id, _supply) \
[_family##_ID_##_id] = {		\
.name			= _name,	\
.supply_name		= _supply,	\
.of_match		= of_match_ptr("REG_"#_id),	\
.regulators_node = of_match_ptr("regulators"),	\
.id			= _family##_ID_##_id,	\
.type			= REGULATOR_VOLTAGE,	\
.ops			= &lombo_ldo_regulator_ops,	\
.enable_reg		= _family##_##_id##_CTRL,	\
.enable_mask	= _family##_##_id##_EN_MASK,\
.owner			= THIS_MODULE,	\
	}

extern struct regulator_ops lombo_dcdc_regulator_ops;
extern struct regulator_ops lombo_ldo_regulator_ops;
extern struct regulator_ops lombo_dummy_regulator_ops;

extern struct regmap_config pmic_regmap;

struct regulator_desc *__get_regulator_desc(void);
int __get_regulators_count(void);
int __pmic_init(struct platform_device *pdev);

#endif
